import request from '@/utils/request'

// 获取文章列表
export const getArticles = (params) => {
  return request({
    url: '/article',
    method: 'get',
    params
  })
}

// 获取单个文章详情
export const getArticle = (id) => {
  return request({
    url: `/article/${id}`,
    method: 'get'
  })
}

// 创建新文章
export const createArticle = (data) => {
  return request({
    url: '/article',
    method: 'post',
    data
  })
}

// 更新文章
export const updateArticle = (id, data) => {
  return request({
    url: `/article/${id}`,
    method: 'put',
    data
  })
}

// 删除文章
export const deleteArticle = (id) => {
  return request({
    url: `/article/${id}`,
    method: 'delete'
  })
}

// 更新文章状态
export const updateArticleStatus = (id, status) => {
  return request({
    url: `/article/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 点赞文章
export const likeArticle = (id) => {
  return request({
    url: `/article/${id}/like`,
    method: 'post'
  })
}

// 取消点赞文章
export const unlikeArticle = (id) => {
  return request({
    url: `/article/${id}/like`,
    method: 'delete'
  })
}

// 收藏文章
export const favoriteArticle = (id) => {
  return request({
    url: `/article/${id}/favorite`,
    method: 'post'
  })
}

// 取消收藏文章
export const unfavoriteArticle = (id) => {
  return request({
    url: `/article/${id}/favorite`,
    method: 'delete'
  })
}

// 获取文章总数
export function getTotalArticles() {
  return request({
    url: '/article/total/articles',
    method: 'get'
  })
}